<?php
namespace Home\Controller;
use Think\Controller;
class MasterController extends PublicController {
    /*大师列表 开发人：周弈男*/
    public function masterlist(){
    	$coach = M('coach');
    	$coach = $coach->join('club ON club.clubid = coach.club')->where("grade=1")->select();
    	$this->assign("master",$coach);
    	$this->display();
    }
    /*大师申请书列表  开发人：周弈男*/
    public function masterapply(){
    	$apply = M('apply');
    	$apply = $apply->join('club ON club.clubid = apply.club')->select();
    	$this->assign("apply",$apply);
    	$this->display();
    }
    /*大师申请书详情  开发人：周弈男*/
    public function applydetail(){
        $id=$_GET['applyid'];
        $apply = M('apply');
        $club=M('club');
        $apply = $apply->where("applyid=$id")->find();
        $map['clubid']=$apply['club'];
        $club=$club->where($map)->find();
        $this->assign(array('apply'=>$apply,'club'=>$club));
        $this->display();
    }
    /*同意  开发人：周弈男*/
    public function agree(){
        $id=$_GET['applyid'];
        $apply = M('apply');
        $coach = M('coach');
        $re = $apply->where("applyid=$id")->find();
        $where['club']=$re['club'];
        $where['coachname']=$re['coach'];
        $data['grade']='1';
        $coach = $coach->where($where)->save($data);
        if($coach=1){
            $apply = $apply->where("applyid=$id")->delete();
            $this -> success('同意成功！',U('masterlist'));
        }else{
            $this->error('同意失败！','');
        }
    }
    /*拒绝  开发人：周弈男*/
    public function refuse(){
        $id=$_GET['applyid'];
        $apply = M('apply');
        $apply = $apply->where("applyid=$id")->delete();
        if($apply=1){
            $this -> success('拒绝成功！',U('masterapply'));
        }else{
            $this->error('拒绝失败！','');
        }
    }
    /*删除大师申请  开发人：周弈男*/
    public function delete(){
        $id=$_GET['applyid'];
        $apply = M('apply');
        $apply = $apply->where("applyid=$id")->delete();
        if($apply=1){
            $this -> success('删除成功！',U('masterapply'));
        }else{
            $this->error('删除失败！','');
        }
    }

    public function cancel(){
        $id=$_GET['coachid'];
        $coach=M('coach');
        $map['grade']='0';
        $coach=$coach->where("coachid=$id")->save($map);
        if($coach){
            $this->success('取消成功！',U('masterlist'));
        }else{
            $this->error('取消失败！','');
        }
    }
}
